package com.zby.lease.web.admin.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zby.lease.model.enums.ItemType;
import com.zby.lease.model.pojo.*;
import com.zby.lease.web.admin.mapper.*;
import com.zby.lease.web.admin.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GeneralService {
    @Autowired
    private GraphInfoService graphInfoService;
    @Autowired
    private RoomFacilityService roomFacilityService;
    @Autowired
    private RoomAttrValueService roomAttrValueService;
    @Autowired
    private RoomLabelService roomLabelService;
    @Autowired
    private RoomPaymentTypeService paymentTypeService;
    @Autowired
    private RoomLeaseTermService leaseTermService;

    public void removeRoomSumById(Long id) {
        LambdaQueryWrapper<GraphInfo> graphQueryWrapper = new LambdaQueryWrapper<>();
        graphQueryWrapper.eq(GraphInfo::getType, ItemType.ROOM);
        graphQueryWrapper.eq(GraphInfo::getItemId, id);
        graphInfoService.remove(graphQueryWrapper);
        //2.删除原有roomAttrValueList
        LambdaQueryWrapper<RoomAttrValue> roomAttrQueryWrapper =  new LambdaQueryWrapper<>();
        roomAttrQueryWrapper.eq(RoomAttrValue::getId, id);
        roomAttrValueService.remove(roomAttrQueryWrapper);
        //3.删除原有roomFacilityList
        LambdaQueryWrapper<RoomFacility> facilityQueryWrapper =  new LambdaQueryWrapper<>();
        facilityQueryWrapper.eq(RoomFacility::getRoomId, id);
        roomFacilityService.remove(facilityQueryWrapper);
        //4.删除原有roomLabelList
        LambdaQueryWrapper<RoomLabel> roomLabelQueryWrapper = new LambdaQueryWrapper<>();
        roomLabelQueryWrapper.eq(RoomLabel::getRoomId, id);
        roomLabelService.remove(roomLabelQueryWrapper);
        //5.删除原有paymentTypeList
        LambdaQueryWrapper<RoomPaymentType> paymentTypeLambdaWrapperp = new LambdaQueryWrapper<>();
        paymentTypeLambdaWrapperp.eq(RoomPaymentType::getId, id);
        paymentTypeService.remove(paymentTypeLambdaWrapperp);
        //6.删除原有leaseTermList
        LambdaQueryWrapper<RoomLeaseTerm> leaseTermLambdaWrapper = new LambdaQueryWrapper<>();
        leaseTermLambdaWrapper.eq(RoomLeaseTerm::getId, id);
        leaseTermService.remove(leaseTermLambdaWrapper);
    }
}
